package com.xmg.p2p.base.controller;

import com.github.pagehelper.PageInfo;
import com.xmg.p2p.base.query.IplogQueryObject;
import com.xmg.p2p.base.service.IplogService;
import com.xmg.p2p.base.util.RequireLogin;
import com.xmg.p2p.base.util.UserContext;
import com.xmg.p2p.business.domain.BidRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @BelongsProject: jinrong-website
 * @BelongsPackage: com.xmg.p2p.base.controller
 * @author: Andy
 * @date: 2020.12.9 19:46
 * @Description: 后台日志登录
 * @since JDK 1.8
 */
@Controller
public class IplogController {
    @Autowired
    private IplogService iplogService;

    /**
     * 个人用户登陆记录列表
     * @param qo
     * @param model
     * @ModelAttribute 如果在方法的参数标记，表示将此参数放到Model里。
     * @return
     */
    @RequireLogin
    @RequestMapping("/ipLog")
    public String iplogList(@ModelAttribute("qo") IplogQueryObject qo, Model model) {
//        把当前登录的用户名传给qo对象
        qo.setUsername(UserContext.getCurrent().getUsername());
        model.addAttribute("pageResult", this.iplogService.query(qo));
        return "ipLog_list";
    }

    @RequestMapping("/logout")
    public String logout(Model model){

        model.addAttribute("bidRequests", null);
        // 设置登录的信息
        UserContext.putCurrent(null);
        // 重定向到main.do页面
        return "main";
    }
}
